﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ProjectBase.Core;

namespace $safeprojectname$.Validation
{
    public class ValidationMessage : System.Collections.IEnumerable
    {
        #region members

        private readonly Severity _severity;
        private readonly string _template;
        private readonly IList<object> _arguments;
        private IEnumerable<ValidationMessage> _innerMessages;

        #endregion members

        #region Constructor

        public ValidationMessage(string template, Severity severity = Severity.Error, IEnumerable<ValidationMessage> innerMessages = null)
        {
            _template = template;
            _severity = severity;
            _innerMessages = innerMessages;
            _arguments = new List<object>();
        }

        #endregion Constructor

        public string Template
        {
            get { return _template; }
        }

        public object[] Arguments
        {
            get { return _arguments.ToArray(); }
        }

        public Severity Severity
        {
            get { return _severity; }
        }

        public virtual IEnumerable<ValidationMessage> InnerMessages
        {
            get { return _innerMessages; }
            set { _innerMessages = value; }
        }

        #region IEnumberable

        public void Add(object argument)
        {
            _arguments.Add(argument);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        protected virtual IEnumerator GetEnumerator()
        {
            return _arguments.GetEnumerator();
        }

        #endregion IEnumberable
    }
}